package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SignToken;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ISignTokenService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 临时签章Controller
 * 
 * @author ess
 * @date 2021-10-18
 */
@RestController
@RequestMapping("/system/signToken")
public class SignTokenController extends BaseController
{
    @Autowired
    private ISignTokenService signTokenService;

    /**
     * 查询临时签章列表
     */
    @PreAuthorize("@ss.hasPermi('system:signToken:list')")
    @GetMapping("/list")
    public TableDataInfo list(SignToken signToken)
    {
        startPage();
        List<SignToken> list = signTokenService.selectSignTokenList(signToken);
        return getDataTable(list);
    }

    /**
     * 导出临时签章列表
     */
    @PreAuthorize("@ss.hasPermi('system:signToken:export')")
    @Log(title = "临时签章", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SignToken signToken)
    {
        List<SignToken> list = signTokenService.selectSignTokenList(signToken);
        ExcelUtil<SignToken> util = new ExcelUtil<SignToken>(SignToken.class);
        return util.exportExcel(list, "临时签章数据");
    }

    /**
     * 获取临时签章详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:signToken:query')")
    @GetMapping(value = "/{tokenId}")
    public AjaxResult getInfo(@PathVariable("tokenId") String tokenId)
    {
        return AjaxResult.success(signTokenService.selectSignTokenByTokenId(tokenId));
    }

    /**
     * 新增临时签章
     */
    @PreAuthorize("@ss.hasPermi('system:signToken:add')")
    @Log(title = "临时签章", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SignToken signToken)
    {
        return toAjax(signTokenService.insertSignToken(signToken));
    }

    /**
     * 修改临时签章
     */
    @PreAuthorize("@ss.hasPermi('system:signToken:edit')")
    @Log(title = "临时签章", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SignToken signToken)
    {
        return toAjax(signTokenService.updateSignToken(signToken));
    }

    /**
     * 删除临时签章
     */
    @PreAuthorize("@ss.hasPermi('system:signToken:remove')")
    @Log(title = "临时签章", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tokenIds}")
    public AjaxResult remove(@PathVariable String[] tokenIds)
    {
        return toAjax(signTokenService.deleteSignTokenByTokenIds(tokenIds));
    }
}
